// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "ReferenceDefine.h"
#include "ICommunicator.h"
#include "mlagents/envs/communicator_objects/unity_to_external.pb.h"
#include "mlagents/envs/communicator_objects/unity_to_external.grpc.pb.h"
/**
 * 
 */
namespace MLAgents {
	class  RPCCommunicator:public ICommunicator
	{
	public:
		RPCCommunicator();
		~RPCCommunicator();

		virtual communicator_objects::UnityInput Initialize(communicator_objects::UnityOutput* unityOutput, communicator_objects::UnityInput & unityInput) override;


		virtual communicator_objects::UnityInput Exchange(communicator_objects::UnityInput* input) override;


		virtual void Close() override;

	public:
		bool m_isOpen;
		std::unique_ptr<communicator_objects::UnityToExternal::Stub> m_client;
		CommunicatorParameters m_communicatorParameters;

		RPCCommunicator(CommunicatorParameters communicatorParameters);
		static Proto::UnityMessage* WrapMessage(Proto::UnityOutput* content, int status);
	private:
		grpc::ClientContext clientContext;

	};

}
